<script>
	import {pxTurnRpx} from '@/common/util';
	export default {
		globalData: {
			highly: 0,
			isWindows: false,
      navigationBarHeight: 0,
      statusBarHeight: 0
		},
		onLaunch: function() {
			const self = this;
			console.warn('当前组件仅支持 uni_modules 目录结构 ，请升级 HBuilderX 到 3.1.0 版本以上！')
			console.log('App Launch');

			// 计算高度
			uni.getSystemInfo({
				success: e => {
					self.globalData.windowHeight = e.windowHeight
					self.globalData.windowWidth = e.windowWidth
					if (e.platform === 'windows') {
						self.globalData.highly = 120
						self.globalData.isWindows = true
					} else {
						self.globalData.highly = (e.screenHeight - e.safeArea.bottom + 48) * pxTurnRpx();
					}
					let menuInfo = wx.getMenuButtonBoundingClientRect();
          self.globalData.statusBarHeight = e.statusBarHeight;
					self.globalData.navigationBarHeight = (menuInfo.top - e.statusBarHeight) * 2 + menuInfo.height;
          uni.setStorageSync('navigationBarHeight', self.globalData.navigationBarHeight);
				}
			});
			// 版本更新
			if (wx.canIUse('getUpdateManager')) {
				const updateManager = wx.getUpdateManager();
				updateManager.onCheckForUpdate(e => {
					console.log('check updater ====', e);
					// 请求新版本信息
					if (e.hasUpdate) {
						updateManager.onUpdateReady(() => {
							wx.showModal({
								title: '更新提示',
								content: '新版本已发布，重启应用更新？',
								cancelColor: '#000000',
								confirmColor: '#FF4953',
								success: e1 => {
									console.log('update success ====', e1);
									if (e1.confirm) {
										// 已下载新版本，调用applyUpdate 启用应版本并重启
										updateManager.applyUpdate();
									}
								}
							})
						});
						updateManager.onUpdateFailed(() => {
							wx.showModal({
								title: '已经有新版本了哟~',
								content: '新版已经上线啦~，请您删除当前小程序，重新搜索打开已体验新内容~',
								confirmText: '知道了',
								confirmColor: '#576B95',
								showCancel: false
							});
						});
					}
				});
			}
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import '@/uni_modules/uni-scss/index.scss';
	/* #ifndef APP-NVUE */
	@import '@/static/customicons.css';

	@import '@/uni.scss';
	// 设置整个项目的背景色
	page {
		background-color: #f5f5f5;
	}

	/* #endif */
	.example-info {
		font-size: 14px;
		color: #333;
		padding: 10px;
	}
</style>
